﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Company.Shell.Converters
{
    /// <summary>
    /// 角色转换器：将数字角色转换为中文显示
    /// </summary>
    public class RoleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int role)
            {
                return role switch
                {
                    1 => "管理员",
                    0 => "操作员",
                    _ => "未知"
                };
            }
            return "未知";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string roleText)
            {
                return roleText switch
                {
                    "管理员" => 1,
                    "操作员" => 0,
                    _ => 0
                };
            }
            return 0;
        }
    }
}